
var vm = new Vue({
    el : "#inspection",
    data : {
        record:{},
        sels:[],
        flyWeavs:[],
        jobStatus:[],
        emesoJobOrderExeId:'',
        table: null
    },
    init:function(){
        var _self = this;
        layui.use(['layer'], function(){
            layer = layui.layer;
        });
        this.$nextTick(function() {
            this.$http.post(host +"cutJob/selectCutJobList",{},{emulateJSON: true}).then(function(res){
                if(res.ok){
                    _self.tableData = res.body.cutJobList;
                    _self.$options.methods.renderTable(_self,res.body.cutJobList);
                }
            });
        });
    },
    methods: {
        SelectLists: function(data){
            var _self = this;



            this.$nextTick(function() {
                this.$http.post(host +"cutJob/selectCutJobList",{},{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.tableData = res.body.zcJobList;
                        _self.$options.methods.renderTable(_self,res.body.zcJobList);


                    }else{
                        layer.msg("查询失败");
                    }
                });
            });
        },
        submitData: function(val){
            var _self = this;
            var userCode = $("#userCode").val();
            if (userCode==null || userCode.trim() =='') {
                alert("请先扫描工号！");
                return;
            }
            var data ={
                status : val,
                userCode:userCode,
                emesoJobOrderExeId:_self.emesoJobOrderExeId
            };
            this.$nextTick(function() {
                this.$http.post(host +"cutJob/submitData",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.vueAlert("操作成功！");


                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        getleftRfidList: function(event){
            document.getElementById("productName").innerText='型体：';
            document.getElementById("orderCode").innerText='规格型号：';
            document.getElementById("colorName").innerText='颜色：';
            document.getElementById("clName").innerText='材料：';
            document.getElementById("processName").innerText='当前工序：';
            document.getElementById("description").innerText='备注：';
            var _self = this;
            /*if (event.keyCode != 13 || !(_self.record.CODE && _self.record.CODE.length > 0)) {

            }*/
            var code = document.getElementById("code").value;   //作业工单RFID
            if(code == null || code.trim() ==''){
                _self.vueAlert("请扫描RFID！");
            }
            _self.changeRfid(_self,code);
            // if (event.ctrlKey && event.keyCode === 67){
            //     _self.changeRfid(_self,code);
            // }else if((event.ctrlKey && !(event.keyCode === 67))||(!event.ctrlKey && event.keyCode === 67)){
            //     return;
            // }else{
            //     _self.changeRfid(_self,code);
            // }

        },
        changeRfid: function(_self,code){


            /*if (event.keyCode != 13 || !(_self.record.CODE && _self.record.CODE.length > 0)) {

            }*/


            var data ={
                code : code
            };
            var cutJobDataByCode = [];
            _self.$nextTick(function() {
                _self.$http.post(host +"cutJob/selectCutJobByCode",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.cutJobDataByCode = res.body.cutJobDataByCode;
                        if(_self.cutJobDataByCode == null || _self.cutJobDataByCode.length == 0){
                            _self.vueAlert("此工单不存在！");
                            return;
                        }
                        cutJobDataByCode =  _self.cutJobDataByCode;
                        if(cutJobDataByCode[0].PRODUCTNAME != null && cutJobDataByCode[0].PRODUCTNAME !=''){
                            document.getElementById("productName").innerText="型体："+cutJobDataByCode[0].PRODUCTNAME;
                        }
                        if(cutJobDataByCode[0].CODE != null && cutJobDataByCode[0].CODE !=''){
                            document.getElementById("orderCode").innerText="规格型号："+cutJobDataByCode[0].CODE;
                        }
                        if(cutJobDataByCode[0].COLORNAME != null && cutJobDataByCode[0].COLORNAME !=''){
                            document.getElementById("colorName").innerText="颜色："+cutJobDataByCode[0].COLORNAME;
                        }
                        if(cutJobDataByCode[0].CLNAME != null && cutJobDataByCode[0].CLNAME !=''){
                            document.getElementById("clName").innerText="材料："+cutJobDataByCode[0].CLNAME;
                        }
                        if(cutJobDataByCode[0].PROCESSNAME != null && cutJobDataByCode[0].PROCESSNAME !=''){
                            document.getElementById("processName").innerText="当前工序："+cutJobDataByCode[0].PROCESSNAME;
                        }
                        if(cutJobDataByCode[0].DESCRIPTION != null && cutJobDataByCode[0].DESCRIPTION !=''){
                            document.getElementById("description").innerText="备注："+cutJobDataByCode[0].DESCRIPTION;
                        }
                        if(cutJobDataByCode[0].STATUSVAL =='ASSIGN' || cutJobDataByCode[0].STATUSVAL =='STOP' ){
                            document.getElementById("defaultBtn").style.display = 'none';
                            document.getElementById("startBtn").style.display = 'block';
                            document.getElementById("finishBtn").style.display = 'none';
                        }else if(cutJobDataByCode[0].STATUSVAL =='START'){
                            document.getElementById("defaultBtn").style.display = 'none';
                            document.getElementById("startBtn").style.display = 'none';
                            document.getElementById("finishBtn").style.display = 'block';
                        }
                        _self.emesoJobOrderExeId = cutJobDataByCode[0].EMESO_JOB_ORDER_EXE_ID;
                    }
                });
            });


        },
        reset:function(data){
            window.location.reload();
        },
        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        renderTable: function(_self,data){
            layui.use(['form','table','laydate'], function(){
                _self.table = layui.table;
                var form = layui.form;

                _self.table.render({
                    elem: '#cdJobListTable',
                    width: 'full-20',
                    height: 'full-150',
                    cols: [[ //标题栏
                        { type:'numbers',title:'序号'},
                        { field: 'CODE', title: '作业工单号',width: 200},
                        {field: 'PRODUCTNAME', title: '型体',width: 200, align:'center' },
                        {field: 'FLNAME', title: '颜色', width: 180,align:'center'},
                        {field: 'FACILITIESNAME', title: '生产设备', width: 150,align:'center'},
                        {field: 'USERNAME', title: '报工人', width: 160,align:'center'},
                        {field: 'EXE_DATE_FROM', title: '开工时间', minWidth: 160,align:'center',templet: "<div>{{layui.util.toDateString(d.EXE_DATE_FROM, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                        {field: 'EXE_DATE_TO', title: '完工时间', minWidth: 160,align:'center',templet: "<div>{{layui.util.toDateString(d.EXE_DATE_TO, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                        {field: 'STATUSNAME', title: '状态', minWidth: 80,align:'center'}

                    ]],
                    data:data,
                    page: true, //是否显示分页
                    limits: [10, 20, 50],
                    limit: 15 //每页默认显示的数量
                });
            });
        }
    }
});